home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / rpm / fts.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-22  |  7.6 KB  |  232 lines

  1. /*
  2.  * Copyright (c) 1989, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 4. Neither the name of the University nor the names of its contributors
  14.  *    may be used to endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  *
  29.  *    @(#)fts.h    8.3 (Berkeley) 8/14/94
  30.  */
  31.  
  32. #ifndef    _FTS_H
  33. #define    _FTS_H 1
  34.  
  35. #if defined(__GLIBC__)
  36. #include <features.h>
  37. #else
  38.  
  39. #   define __THROW
  40. #ifdef  __cplusplus
  41. # define __BEGIN_DECLS  extern "C" {
  42. # define __END_DECLS    }
  43. #else
  44. # define __BEGIN_DECLS
  45. # define __END_DECLS
  46. #endif
  47.  
  48. #if defined(hpux)
  49. # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
  50. # define    _INCLUDE_POSIX_SOURCE
  51. # define    _LARGEFILE64_SOURCE
  52. #endif
  53.  
  54. #if defined(sun)
  55. # define _D_EXACT_NAMLEN(d) ((d)->d_reclen)
  56. #endif
  57.  
  58. #if defined(__APPLE__)
  59. # define _D_EXACT_NAMLEN(d) (strlen((d)->d_name))
  60. #endif
  61.  
  62. #endif
  63.  
  64. #include <sys/types.h>
  65. #include <sys/stat.h>
  66. #include <dirent.h>
  67.  
  68. typedef struct {
  69. /*@owned@*/ /*@relnull@*/
  70.     struct _ftsent *fts_cur;    /*!< current node */
  71. /*@owned@*/ /*@null@*/
  72.     struct _ftsent *fts_child;    /*!< linked list of children */
  73. /*@owned@*/ /*@null@*/
  74.     struct _ftsent **fts_array;    /*!< sort array */
  75.     dev_t fts_dev;            /*!< starting device # */
  76. /*@owned@*/ /*@relnull@*/
  77.     char *fts_path;            /*!< path for this descent */
  78.     int fts_rfd;            /*!< fd for root */
  79.     int fts_pathlen;        /*!< sizeof(path) */
  80.     int fts_nitems;            /*!< elements in the sort array */
  81. /*@null@*/
  82.     int (*fts_compar) (const void *, const void *)
  83.         /*@*/;            /*!< compare fn */
  84.  
  85.     DIR * (*fts_opendir) (const char * path)
  86.         /*@globals fileSystem @*/
  87.         /*@modifies fileSystem @*/;
  88.     struct dirent * (*fts_readdir) (DIR * dir)
  89.         /*@globals fileSystem @*/
  90.         /*@modifies *dir, fileSystem @*/;
  91.     int (*fts_closedir) (/*@only@*/ DIR * dir)
  92.         /*@globals fileSystem @*/
  93.         /*@modifies *dir, fileSystem @*/;
  94.     int (*fts_stat) (const char * path, /*@out@*/ struct stat * st)
  95.         /*@globals fileSystem @*/
  96.         /*@modifies *st, fileSystem @*/;
  97.     int (*fts_lstat) (const char * path, /*@out@*/ struct stat * st)
  98.         /*@globals fileSystem @*/
  99.         /*@modifies *st, fileSystem @*/;
  100.  
  101. #define    FTS_COMFOLLOW    0x0001        /* follow command line symlinks */
  102. #define    FTS_LOGICAL    0x0002        /* logical walk */
  103. #define    FTS_NOCHDIR    0x0004        /* don't change directories */
  104. #define    FTS_NOSTAT    0x0008        /* don't get stat info */
  105. #define    FTS_PHYSICAL    0x0010        /* physical walk */
  106. #define    FTS_SEEDOT    0x0020        /* return dot and dot-dot */
  107. #define    FTS_XDEV    0x0040        /* don't cross devices */
  108. #define FTS_WHITEOUT    0x0080        /* return whiteout information */
  109. #define    FTS_OPTIONMASK    0x00ff        /* valid user option mask */
  110.  
  111. #define    FTS_NAMEONLY    0x0100        /* (private) child names only */
  112. #define    FTS_STOP    0x0200        /* (private) unrecoverable error */
  113.     int fts_options;        /*!< fts_open options, global flags */
  114. } FTS;
  115.  
  116. typedef struct _ftsent {
  117. /*@dependent@*/
  118.     struct _ftsent *fts_cycle;    /*!< cycle node */
  119. /*@dependent@*/ /*@relnull@*/
  120.     struct _ftsent *fts_parent;    /*!< parent directory */
  121. /*@dependent@*/ /*@null@*/
  122.     struct _ftsent *fts_link;    /*!< next file in directory */
  123.     long fts_number;            /*!< local numeric value */
  124. /*@null@*/
  125.     void *fts_pointer;            /*!< local address value */
  126. /*@dependent@*/
  127.     char *fts_accpath;        /*!< access path */
  128. /*@dependent@*/
  129.     char *fts_path;            /*!< root path */
  130.     int fts_errno;            /*!< errno for this node */
  131.     int fts_symfd;            /*!< fd for symlink */
  132.     u_short fts_pathlen;        /*!< strlen(fts_path) */
  133.     u_short fts_namelen;        /*!< strlen(fts_name) */
  134.  
  135.     ino_t fts_ino;            /*!< inode */
  136.     dev_t fts_dev;            /*!< device */
  137.     nlink_t fts_nlink;        /*!< link count */
  138.  
  139. #define    FTS_ROOTPARENTLEVEL    -1
  140. #define    FTS_ROOTLEVEL         0
  141.     short fts_level;        /*!< depth (-1 to N) */
  142.  
  143. #define    FTS_D         1        /* preorder directory */
  144. #define    FTS_DC         2        /* directory that causes cycles */
  145. #define    FTS_DEFAULT     3        /* none of the above */
  146. #define    FTS_DNR         4        /* unreadable directory */
  147. #define    FTS_DOT         5        /* dot or dot-dot */
  148. #define    FTS_DP         6        /* postorder directory */
  149. #define    FTS_ERR         7        /* error; errno is set */
  150. #define    FTS_F         8        /* regular file */
  151. #define    FTS_INIT     9        /* initialized only */
  152. #define    FTS_NS        10        /* stat(2) failed */
  153. #define    FTS_NSOK    11        /* no stat(2) requested */
  154. #define    FTS_SL        12        /* symbolic link */
  155. #define    FTS_SLNONE    13        /* symbolic link without target */
  156. #define FTS_W        14        /* whiteout object */
  157.     u_short fts_info;        /*!< user flags for FTSENT structure */
  158.  
  159. #define    FTS_DONTCHDIR     0x01        /* don't chdir .. to the parent */
  160. #define    FTS_SYMFOLLOW     0x02        /* followed a symlink to get here */
  161.     u_short fts_flags;        /*!< private flags for FTSENT structure */
  162.  
  163. #define    FTS_AGAIN     1        /* read node again */
  164. #define    FTS_FOLLOW     2        /* follow symbolic link */
  165. #define    FTS_NOINSTR     3        /* no instructions */
  166. #define    FTS_SKIP     4        /* discard node */
  167.     u_short fts_instr;        /*!< fts_set() instructions */
  168.  
  169. /*@dependent@*/
  170.     struct stat *fts_statp;        /*!< stat(2) information */
  171.     char fts_name[1];        /*!< file name */
  172. } FTSENT;
  173.  
  174. __BEGIN_DECLS
  175.  
  176. /**
  177.  * Return list of children of the current node.
  178.  * @param sp        file hierarchy state
  179.  * @param instr
  180.  * @return        file set member
  181.  */
  182. /*@dependent@*/ /*@null@*/
  183. FTSENT    *Fts_children (FTS * sp, int instr) __THROW
  184.     /*@globals fileSystem, internalState @*/
  185.     /*@modifies *sp, fileSystem, internalState @*/;
  186.  
  187. /**
  188.  * Destroy a file hierarchy traversal handle.
  189.  * @param sp        file hierarchy state
  190.  * @return        0 on sucess, -1 on error
  191.  */
  192. int     Fts_close (/*@only@*/ /*@null@*/ FTS * sp) __THROW
  193.     /*@globals fileSystem, internalState @*/
  194.     /*@modifies *sp, fileSystem, internalState @*/;
  195.  
  196. /**
  197.  * Create a handle for file hierarchy traversal.
  198.  * @param argv        paths that compose a logical file hierarchy
  199.  * @param options    traversal options
  200.  * @param compar    traversal ordering (or NULL)
  201.  * @return         file hierarchy state (or NULL on error)
  202.  */
  203. /*@only@*/ /*@null@*/
  204. FTS    *Fts_open (char * const * argv, int options,
  205.            /*@null@*/
  206.            int (*compar) (const FTSENT **, const FTSENT **)) __THROW
  207.     /*@*/;
  208.  
  209. /**
  210.  * Return next node in the file hierarchy traversal.
  211.  * @param sp        file hierarchy state
  212.  * @return        file set member
  213.  */
  214. /*@null@*/
  215. FTSENT    *Fts_read (/*@null@*/ FTS * sp) __THROW
  216.     /*@globals fileSystem, internalState @*/
  217.     /*@modifies *sp, fileSystem, internalState @*/;
  218.  
  219. /**
  220.  * Modify the traversal for a file set member.
  221.  * @param sp        file hierarchy state
  222.  * @param p        file set member
  223.  * @param instr        new disposition for file set member
  224.  * @return        0 on sucess, -1 on error
  225.  */
  226. int     Fts_set (FTS * sp, FTSENT * p, int instr) __THROW
  227.     /*@modifies *p @*/;
  228.  
  229. __END_DECLS
  230.  
  231. #endif /* fts.h */
  232.